<?php 
include 'ini.php';
include 'header.php';
if (isLoggedIn())
{
    $testAttemptID = $_GET['t_id'];
    
    $englishTotal = getTotalScoreForSection(1, $testAttemptID);
    $mathTotal = getTotalScoreForSection(2, $testAttemptID);
    $readingTotal = getTotalScoreForSection(3, $testAttemptID);
    $scienceTotal = getTotalScoreForSection(4, $testAttemptID);
    
    $scaledEnglish = getScaledEnglishScore($englishTotal);
    $scaledMath = getScaledMathScore($mathTotal);
    $scaledReading = getScaledReadingScore($readingTotal);
    $scaledScience = getScaledScienceScore($scienceTotal);
    
    $testId = getTestIdFromTestAttempt($testAttemptID);    
    $dateTaken = date('M j, Y', strtotime(getDateForTestAttempt($testAttemptID)));
    
    $fullComposite = round(($scaledEnglish + $scaledMath + $scaledReading + $scaledScience) / 4);
    
    
    $englishArray = getAnswerArrayFor($testId, 1);
    $englishCorrectAnswers = $englishArray[0];
    $englishQuestionIds = $englishArray[1];
    
    $mathArray = getAnswerArrayFor($testId, 2);
    $mathCorrectAnswers = $mathArray[0];
    $mathQuestionIds = $mathArray[1];
    
    $readingArray = getAnswerArrayFor($testId, 3);
    $readingCorrectAnswers = $readingArray[0];
    $readingQuestionIds = $readingArray[1];
    
    $scienceArray = getAnswerArrayFor($testId, 4);
    $scienceCorrectAnswers = $scienceArray[0];
    $scienceQuestionIds = $scienceArray[1];

?>
<h2 style="margin-top: 0px; padding-top: 0px;">Detailed Score Report</h2>
<div class="test_info_topper">
    <div class="test_info"><strong>Test ID:</strong> <?php echo $testId;?> </div>
      <div class="test_info"><strong>Date scored: </strong><?php echo $dateTaken;?> </div>
    </div>
      <div class="composite_score_wrapper">


<div class="composite_score">
    Score:
</div>
    <div class="composite_score_right">
        <?php echo $fullComposite;?>
    </div>
</div>
<div class="clearFix"></div>

    
<table class="table table-bordered" style="text-align: center; margin-top: 20px;">
      <thead>
        <tr>
        <th style="width: 150px;"></th>
          <th style="font-size: 18px; text-align: center; background-color:  #5bc0de;">English</th>
          <th style="font-size: 18px; text-align: center; background-color: #4cae4c;">Math</th>
          <th style="font-size: 18px; text-align: center; background-color:  #eea236">Reading</th>
          <th style="font-size: 18px; text-align: center; background-color: #d43f3a">Science</th>
        </tr>
      </thead>
      <tbody>
        <tr>
            <td style="font-size: 16px; font-weight: bold;">Scale Score<br> (1 - 36)</td>
          <td class="scaled_score"><?php echo $scaledEnglish;?></td>
          <td  class="scaled_score"><?php echo $scaledMath;?></td>
          <td  class="scaled_score"><?php echo $scaledReading;?></td>
          <td  class="scaled_score"><?php echo $scaledScience;?></td>
        </tr>
        <tr>
          <td style="font-size: 14px; font-weight: bold;">Actual score</td>
          <td><?php echo $englishTotal;?> / 75</td>
          <td><?php echo $mathTotal;?> / 60</td>
          <td><?php echo $readingTotal;?> / 40</td>
          <td><?php echo $scienceTotal;?> / 40</td>
        </tr>
      </tbody>
    </table>



<div class="clearFix"></div>
    
<fieldset class="">
    <legend>English</legend>
<table class="table borderless" style="text-align: center; margin-top: 20px; background-color: #f8f8f8">
    <tr>
        <td class="test_detail_leftmostcol">QUESTION</td>
     <?php
        for($i = 1; $i < 26; $i++)
        {
            echo "<td>".$i."</td>";
        }
       ?>
    </tr>
    <tr>
        <td class="test_detail_leftmostcol">KEY</td>
        <?php
        for($i = 0; $i < 25; $i++)
        {
            echo "<td style='font-weight: bold; color: #222;'>".strtoupper($englishCorrectAnswers[$i])."</td>";
        }
       ?>
    </tr>
    
    <tr>
        <td class="test_detail_leftmostcol">STUDENT</td>
         <?php
        for($i = 0; $i < 25; $i++)
        {
            $selectedAnswer = getSelectedAnswerFor($testAttemptID, $englishQuestionIds[$i]);
            
            if (strcasecmp($englishCorrectAnswers[$i], $selectedAnswer) == 0)
            {
                echo "<td style='color: #2DBB28;'>&#x2713;</td>";
            }
            else
            {
                echo "<td style='color: red; font-weight: bold;'>".strtoupper($selectedAnswer)."</td>";
            }
        }
       ?>
    </tr>
    
</table>
    
    
    
    <div class="clearFix"></div>
    <table class="table borderless" style="text-align: center; margin-top: 20px; background-color: #f8f8f8">
    <tr>
        <td class="test_detail_leftmostcol"></td>
     <?php
        for($i = 26; $i < 51; $i++)
        {
            echo "<td>".$i."</td>";
        }
       ?>
    </tr>
    <tr>
        <td class="test_detail_leftmostcol"></td>
        <?php
        for($i = 25; $i < 50; $i++)
        {
            echo "<td style='font-weight: bold; color: #222;'>".strtoupper($englishCorrectAnswers[$i])."</td>";
        }
       ?>
    </tr>
    
    <tr>
        <td class="test_detail_leftmostcol"></td>
         <?php
        for($i = 25; $i < 50; $i++)
        {
            $selectedAnswer = getSelectedAnswerFor($testAttemptID, $englishQuestionIds[$i]);
            
            if (strcasecmp($englishCorrectAnswers[$i], $selectedAnswer) == 0)
            {
                echo "<td style='color: #2DBB28;'>&#x2713;</td>";
            }
            else
            {
                echo "<td style='color: red; font-weight: bold;'>".strtoupper($selectedAnswer)."</td>";
            }
        }
       ?>
    </tr>
    
</table>
    
    
    <div class="clearFix"></div>
    <table class="table borderless" style="text-align: center; margin-top: 20px; background-color: #f8f8f8">
    <tr>
        <td class="test_detail_leftmostcol"></td>
     <?php
        for($i = 51; $i < 76; $i++)
        {
            echo "<td>".$i."</td>";
        }
       ?>
    </tr>
    <tr>
        <td class="test_detail_leftmostcol"></td>
        <?php
        for($i = 50; $i < 75; $i++)
        {
            echo "<td style='font-weight: bold; color: #222;'>".strtoupper($englishCorrectAnswers[$i])."</td>";
        }
       ?>
    </tr>
    
    <tr>
        <td class="test_detail_leftmostcol"></td>
         <?php
        for($i = 50; $i < 75; $i++)
        {
            $selectedAnswer = getSelectedAnswerFor($testAttemptID, $englishQuestionIds[$i]);
            
            if (strcasecmp($englishCorrectAnswers[$i], $selectedAnswer) == 0)
            {
                echo "<td style='color: #2DBB28;'>&#x2713;</td>";
            }
            else
            {
                echo "<td style='color: red; font-weight: bold;'>".strtoupper($selectedAnswer)."</td>";
            }
        }
       ?>
    </tr>
    
</table>    
</fieldset>
<div class="clearFix"></div>







<fieldset class="">
    <legend>Math</legend>
<table class="table borderless" style="text-align: center; margin-top: 20px; background-color: #f8f8f8">
    <tr>
        <td class="test_detail_leftmostcol">QUESTION</td>
     <?php
        for($i = 1; $i < 26; $i++)
        {
            echo "<td>".$i."</td>";
        }
       ?>
    </tr>
    <tr>
        <td class="test_detail_leftmostcol">KEY</td>
        <?php
        for($i = 0; $i < 25; $i++)
        {
            echo "<td style='font-weight: bold; color: #222;'>".strtoupper($mathCorrectAnswers[$i])."</td>";
        }
       ?>
    </tr>
    
    <tr>
        <td class="test_detail_leftmostcol">STUDENT</td>
         <?php
        for($i = 0; $i < 25; $i++)
        {
            $selectedAnswer = getSelectedAnswerFor($testAttemptID, $mathQuestionIds[$i]);
            
            if (strcasecmp($mathCorrectAnswers[$i], $selectedAnswer) == 0)
            {
                echo "<td style='color: #2DBB28;'>&#x2713;</td>";
            }
            else
            {
                echo "<td style='color: red; font-weight: bold;'>".strtoupper($selectedAnswer)."</td>";
            }
        }
       ?>
    </tr>
    
</table>  
    
    
    <div class="clearFix"></div>

    <table class="table borderless" style="text-align: center; margin-top: 20px; background-color: #f8f8f8;">
    <tr>
        <td class="test_detail_leftmostcol"></td>
     <?php
        for($i = 26; $i < 51; $i++)
        {
            echo "<td>".$i."</td>";
        }
       ?>
    </tr>
    <tr>
        <td class="test_detail_leftmostcol"></td>
        <?php
        for($i = 25; $i < 50; $i++)
        {
            echo "<td style='font-weight: bold; color: #222;'>".strtoupper($mathCorrectAnswers[$i])."</td>";
        }
       ?>
    </tr>
    
    <tr>
        <td class="test_detail_leftmostcol"></td>
         <?php
        for($i = 25; $i < 50; $i++)
        {
            $selectedAnswer = getSelectedAnswerFor($testAttemptID, $mathQuestionIds[$i]);
            
            if (strcasecmp($mathCorrectAnswers[$i], $selectedAnswer) == 0)
            {
                echo "<td style='color: #2DBB28;'>&#x2713;</td>";
            }
            else
            {
                echo "<td style='color: red; font-weight: bold;'>".strtoupper($selectedAnswer)."</td>";
            }
        }
       ?>
    </tr>
    
</table>
    <div class="clearFix"></div>
    <table class="table borderless" style="text-align: center; margin-top: 20px; background-color: #f8f8f8">
    <tr>
        <td class="test_detail_leftmostcol"></td>
     <?php
        for($i = 51; $i < 61; $i++)
        {
            echo "<td>".$i."</td>";
        }
        
        for($i = 0; $i < 15; $i++)
        {
            echo "<td style='width: 35px;'> </td>";
        }
       ?>
    </tr>
    <tr>
        <td class="test_detail_leftmostcol"></td>
        <?php
        for($i = 50; $i < 60; $i++)
        {
            echo "<td style='font-weight: bold; color: #222;'>".strtoupper($mathCorrectAnswers[$i])."</td>";
        }
        
         for($i = 0; $i < 15; $i++)
        {
            echo "<td> </td>";
        }
       ?>
    </tr>
    
    <tr>
        <td class="test_detail_leftmostcol"></td>
         <?php
        for($i = 50; $i < 60; $i++)
        {
            $selectedAnswer = getSelectedAnswerFor($testAttemptID, $mathQuestionIds[$i]);
            
            if (strcasecmp($mathCorrectAnswers[$i], $selectedAnswer) == 0)
            {
                echo "<td style='color: #2DBB28;'>&#x2713;</td>";
            }
            else
            {
                echo "<td style='color: red; font-weight: bold;'>".strtoupper($selectedAnswer)."</td>";
            }
        }
        
         for($i = 0; $i < 15; $i++)
        {
            echo "<td> </td>";
        }
       ?>
    </tr>
</table>
</fieldset>
    
    
    
    



















<fieldset class="">
    <legend>Reading</legend>
<table class="table borderless" style="text-align: center; margin-top: 20px; background-color: #f8f8f8">
    <tr>
        <td class="test_detail_leftmostcol">QUESTION</td>
     <?php
        for($i = 1; $i < 26; $i++)
        {
            echo "<td>".$i."</td>";
        }
       ?>
    </tr>
    <tr>
        <td class="test_detail_leftmostcol">KEY</td>
        <?php
        for($i = 0; $i < 25; $i++)
        {
            echo "<td style='font-weight: bold; color: #222;'>".strtoupper($readingCorrectAnswers[$i])."</td>";
        }
       ?>
    </tr>
    
    <tr>
        <td class="test_detail_leftmostcol">STUDENT</td>
         <?php
        for($i = 0; $i < 25; $i++)
        {
            $selectedAnswer = getSelectedAnswerFor($testAttemptID, $readingQuestionIds[$i]);
            
            if (strcasecmp($readingCorrectAnswers[$i], $selectedAnswer) == 0)
            {
                echo "<td style='color: #2DBB28;'>&#x2713;</td>";
            }
            else
            {
                echo "<td style='color: red; font-weight: bold;'>".strtoupper($selectedAnswer)."</td>";
            }
        }
       ?>
    </tr>
    
</table>  
    
    
    <div class="clearFix"></div>

    <table class="table borderless" style="text-align: center; margin-top: 20px; background-color: #f8f8f8;">
    <tr>
        <td class="test_detail_leftmostcol"></td>
     <?php
        for($i = 26; $i < 41; $i++)
        {
            echo "<td>".$i."</td>";
        }
        
         for($i = 0; $i < 10; $i++)
        {
            echo "<td style='width: 35px;'> </td>";
        }
       ?>
    </tr>
    <tr>
        <td class="test_detail_leftmostcol"></td>
        <?php
        for($i = 25; $i < 40; $i++)
        {
            echo "<td style='font-weight: bold; color: #222;'>".strtoupper($readingCorrectAnswers[$i])."</td>";
        }
        
         for($i = 0; $i < 10; $i++)
        {
            echo "<td style='width: 35px;'> </td>";
        }
       ?>
    </tr>
    
    <tr>
        <td class="test_detail_leftmostcol"></td>
         <?php
        for($i = 25; $i < 40; $i++)
        {
            $selectedAnswer = getSelectedAnswerFor($testAttemptID, $readingQuestionIds[$i]);
            
            if (strcasecmp($readingCorrectAnswers[$i], $selectedAnswer) == 0)
            {
                echo "<td style='color: #2DBB28;'>&#x2713;</td>";
            }
            else
            {
                echo "<td style='color: red; font-weight: bold;'>".strtoupper($selectedAnswer)."</td>";
            }
        }
        
        for($i = 0; $i < 10; $i++)
        {
            echo "<td style='width: 35px;'> </td>";
        }
       ?>
    </tr>
    
</table>
 </fieldset>




















<fieldset class="">
    <legend>Science</legend>
<table class="table borderless" style="text-align: center; margin-top: 20px; background-color: #f8f8f8">
    <tr>
        <td class="test_detail_leftmostcol">QUESTION</td>
     <?php
        for($i = 1; $i < 26; $i++)
        {
            echo "<td>".$i."</td>";
        }
       ?>
    </tr>
    <tr>
        <td class="test_detail_leftmostcol">KEY</td>
        <?php
        for($i = 0; $i < 25; $i++)
        {
            echo "<td style='font-weight: bold; color: #222;'>".strtoupper($scienceCorrectAnswers[$i])."</td>";
        }
       ?>
    </tr>
    
    <tr>
        <td class="test_detail_leftmostcol">STUDENT</td>
         <?php
        for($i = 0; $i < 25; $i++)
        {
            $selectedAnswer = getSelectedAnswerFor($testAttemptID, $scienceQuestionIds[$i]);
            
            if (strcasecmp($scienceCorrectAnswers[$i], $selectedAnswer) == 0)
            {
                echo "<td style='color: #2DBB28;'>&#x2713;</td>";
            }
            else
            {
                echo "<td style='color: red; font-weight: bold;'>".strtoupper($selectedAnswer)."</td>";
            }
        }
       ?>
    </tr>
    
</table>  
    
    
    <div class="clearFix"></div>

    <table class="table borderless" style="text-align: center; margin-top: 20px; background-color: #f8f8f8;">
    <tr>
        <td class="test_detail_leftmostcol"></td>
     <?php
        for($i = 26; $i < 41; $i++)
        {
            echo "<td>".$i."</td>";
        }
        
         for($i = 0; $i < 10; $i++)
        {
            echo "<td style='width: 35px;'> </td>";
        }
       ?>
    </tr>
    <tr>
        <td class="test_detail_leftmostcol"></td>
        <?php
        for($i = 25; $i < 40; $i++)
        {
            echo "<td style='font-weight: bold; color: #222;'>".strtoupper($scienceCorrectAnswers[$i])."</td>";
        }
        
         for($i = 0; $i < 10; $i++)
        {
            echo "<td style='width: 35px;'> </td>";
        }
       ?>
    </tr>
    
    <tr>
        <td class="test_detail_leftmostcol"></td>
         <?php
        for($i = 25; $i < 40; $i++)
        {
            $selectedAnswer = getSelectedAnswerFor($testAttemptID, $scienceQuestionIds[$i]);
            
            if (strcasecmp($scienceCorrectAnswers[$i], $selectedAnswer) == 0)
            {
                echo "<td style='color: #2DBB28;'>&#x2713;</td>";
            }
            else
            {
                echo "<td style='color: red; font-weight: bold;'>".strtoupper($selectedAnswer)."</td>";
            }
        }
        
        for($i = 0; $i < 10; $i++)
        {
            echo "<td style='width: 35px;'> </td>";
        }
       ?>
    </tr>
    
</table>
 </fieldset>
    
    
<?php
}
else
{
    ?>

<?php
}
